<template>
  <el-collapse class="base-detail" v-model="on" v-if="show === false">
      <el-collapse-item name="1">
        <template slot="title">
          基础信息
          <span :class="state.base_chk_status === 10 ? 'tip' : state.base_chk_status === 20 ? 'succ' : state.base_chk_status === -10 ? 'err' : state.base_chk_status === 0 ? '' : ''">
           （ {{ state.base_chk_status === 10 ? '待审核' : state.base_chk_status === 20 ? '已通过' : state.base_chk_status === -10 ? '审核未通过' : state.base_chk_status === 0 ? '未提交' : '' }} ）
          </span>
        </template>
        <detail-base :data="base" @update="handleEmitUpdate"></detail-base>
      </el-collapse-item>
      <el-collapse-item name="2">
        <template slot="title">
          账户信息
          <span :class="state.bank_chk_status === 10 ? 'tip' : state.bank_chk_status === 20 ? 'succ' : state.bank_chk_status === -10 ? 'err' : state.bank_chk_status === 0 ? '' : ''">
           （ {{ state.bank_chk_status === 10 ? '待审核' : state.bank_chk_status === 20 ? '已通过' : state.bank_chk_status === -10 ? '审核未通过' : state.bank_chk_status === 0 ? '未提交' : '' }} ）
          </span>
        </template>
        <detail-account :data="bank" :merchantType="base.type" :merchantNum="base.merchant_num" @update="handleEmitUpdate"></detail-account>
      </el-collapse-item>
      <el-collapse-item name="3">
        <template slot="title">
          法人信息
          <span :class="state.leader_chk_status === 10 ? 'tip' : state.leader_chk_status === 20 ? 'succ' : state.leader_chk_status === -10 ? 'err' : state.leader_chk_status === 0 ? '' : ''">
           （ {{ state.leader_chk_status === 10 ? '待审核' : state.leader_chk_status === 20 ? '已通过' : state.leader_chk_status === -10 ? '审核未通过' : state.leader_chk_status === 0 ? '未提交' : '' }} ）
          </span>
        </template>
        <detail-principal :data="leader" :contactType="base.bus_licence_type" :merchantNum="base.merchant_num" @update="handleEmitUpdate"></detail-principal>
      </el-collapse-item>
      <el-collapse-item name="4">
        <template slot="title">
          联系人信息
          <span :class="state.contact_chk_status === 10 ? 'tip' : state.contact_chk_status === 20 ? 'succ' : state.contact_chk_status === -10 ? 'err' : state.contact_chk_status === 0 ? '' : ''">
           （ {{ state.contact_chk_status === 10 ? '待审核' : state.contact_chk_status === 20 ? '已通过' : state.contact_chk_status === -10 ? '审核未通过' : state.contact_chk_status === 0 ? '未提交' : '' }} ）
          </span>
        </template>
        <detail-contacts :data="contact" :merchantNum="base.merchant_num" @update="handleEmitUpdate"></detail-contacts>
      </el-collapse-item>
      <el-collapse-item name="5">
        <template slot="title">
          微信公众号关注
        </template>
        <detail-wechat :data="wx" :merchantNum="base.merchant_num" @update="handleEmitUpdate"></detail-wechat>
      </el-collapse-item>
    </el-collapse>
</template>

<script>
import detailBase from './detail-base'
import detailAccount from './detail-account'
import detailPrincipal from './detail-principal'
import detailContacts from './detail-contacts'
import detailWechat from './detail-wechat'
import { baseDetailsInit } from '@/api/shop'

export default {
  components: {
    detailBase,
    detailAccount,
    detailPrincipal,
    detailContacts,
    detailWechat
  },
  data() {
    return {
      on: [],
      state: {},
      loading: true,
      show: true,
      base: null,
      bank: null,
      contact: null,
      leader: null,
      wx: null
    }
  },
  created() {
    this.handleDocumentInit()
  },
  methods: {
    handleDocumentInit() {
      baseDetailsInit(this.$route.query.merchant_num).then(res => {
        if (res.data.errorCode === 0) {
          this.base = res.data.result.base
          this.bank = res.data.result.bank
          this.contact = res.data.result.contact
          this.leader = res.data.result.leader
          this.wx = res.data.result.weixinpub
          this.state = res.data.result.info_status
          this.show = false
        } else {
          this.$message.error('数据加载失败，请刷新重试~')
        }
      })
    },
    handleEmitUpdate() {
      baseDetailsInit(this.$route.query.merchant_num).then(res => {
        if (res.data.errorCode === 0) {
          this.base = res.data.result.base
          this.bank = res.data.result.bank
          this.contact = res.data.result.contact
          this.leader = res.data.result.leader
          this.wx = res.data.result.weixinpub
          this.state = res.data.result.info_status
          this.show = false
        } else {
          this.$message.error('数据加载失败，请刷新重试~')
        }
      })
    }
  }
}
</script>